<?php
class Menu_View_Helper_MenuLoader extends Zend_View_Helper_Abstract
{
	public function menuLoader($menuId = 5) {
        //$menuId = $this->_request->getParam('menu_id');
        $conn = Tomato_Db_Connection::factory()->getSlaveConnection();
        $itemDao = Tomato_Model_Dao_Factory::getInstance()->setModule('menu')->getItemDao();
        $itemDao->setDbConnection($conn);
        
        $items = $itemDao->getTree($menuId);
        
        /**
         * Use Zend_Navigation to render the menu
         * @since 2.0.7
         */
        $container = new Zend_Navigation();
        foreach ($items as $item) {
            $page = new Zend_Navigation_Page_Uri(array(
                'label' => $item->label,
                'uri'   => $item->link,
                'id'    => $item->item_id,
            ));
            
            if ($item->parent_id == 0) {
                $container->addPage($page);
            } else {
                $page->setParent($container->findOneById($item->parent_id));
            }
        }
        
        $this->view->assign('uuid', uniqid());
        $this->view->assign('container', $container);
        
        $this->view->addScriptPath(TOMATO_APP_DIR . DS . 'modules' . DS . 'menu' . DS . 'views' . DS . 'scripts');
        return $this->view->render('_partial/_menu.phtml');
	}
}